#ifndef _DRV_CALIB_
#define _DRV_CALIB_
#include "stdint.h"
#include "stdlib.h"
#include "stdio.h"
#define BAUD_DEFAULT (20)
typedef struct
{
	uint8_t addr;
	uint8_t baud;
	uint8_t status;
	uint8_t old_status;
}_device_t;
typedef struct
{
	int16_t now_dat;
	int16_t old_dat;
	uint16_t time;
	uint16_t temp;
	int16_t  rateres;
	int16_t delta;
	int16_t	positive;
}rate_t;

typedef struct
{
	int16_t x;
	int16_t y;
}point_t;
typedef struct
{
	uint16_t lmt_h;
	uint16_t lmt_l;
}_lmt_t;
typedef struct
{
	uint8_t use;
	uint8_t lv;
	uint8_t isrdy;
	uint16_t	warmTime;
	uint8_t (*fwarm)(void);
}_status_t;
typedef struct
{
	uint8_t needcalib_fla;
	uint8_t calib_num;	
	point_t calib_arr[10];	
}_calib_t;

typedef struct _sensor_t
{
	uint8_t		*name;
	_status_t	sta;
	_lmt_t			lmt_buf;
	_calib_t 	calib_buf;
	uint16_t 	ad;
	int16_t 	val;
	uint16_t	(*fgetAD)(void);
	int16_t 	(*fcovVAL)(struct _sensor_t *_t);//int16_t ad,point_t *calib_arr,uint8_t calib_num
	int16_t 	(*fconvert_val_dir)(int16_t ad);
	int16_t 	(*_rate_cal)(struct _sensor_t *_t);
	rate_t    rate;
	point_t		val_x_y;
}_sensor_t;
extern _sensor_t  sensor_t[],*p_h2,*p_co,*p_smk,*p_t1,*p_t2;

extern _status_t  status_t[];
extern _lmt_t		 lmt_t[];
extern _calib_t   calib_t[];
extern _device_t	device_t;
void _sensor_init(_sensor_t *_t,uint8_t *s,_status_t *sta,_lmt_t *lmt,_calib_t *calib);
void _sendor_run(_sensor_t *_t);
void _sensor_lmt_det(_sensor_t *_t);
int16_t _rate_cal(_sensor_t *_t);

void _sensor_rate_cfg(_sensor_t *_t,uint16_t time,int16_t 	(*_rate_cal)(struct _sensor_t *_t));
void _sensor_fad_cfg(_sensor_t *_t,uint16_t	(*fgetAD)(void));
void _sensor_fcovVAL(_sensor_t *_t,int16_t 	(*fcovVAL)( _sensor_t *_t),int16_t 	(*fconvert_val_dir)(int16_t ad));
int16_t _fcovCalib_val(_sensor_t *_t);
int16_t convert_val(int16_t ad,point_t *calib_arr,uint8_t calib_num);

void del_point(uint8_t index,uint8_t *total,point_t *calib_arr);
void add_point(point_t data,  uint8_t *total,point_t *calib_arr);
uint8_t point_sort(point_t *point, uint8_t len);
#define SENSOR_NUM 5 
#define CALIB_ARR_SIZE 10
#define SENSOR_H_ALARM 	1
#define SENSOR_L_ALARM	2
#define SENSOR_NORMAL		0
#endif